﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-28>
//创建作者：<郭登杰>
//功能说明：来函水表信息列表
//********************************************************************************//
using BLL.Access;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL;
using DevExpress.Web;

namespace Web.Controls
{
    public partial class UCLHShuiBiaoListQSK : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        /// 来函流程步骤
        /// </summary>
        public eLaiHanLCBH LaiHanLC {
            get
            {
                return ViewState["LaiHanLC"]==null?eLaiHanLCBH.未登记:(eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), Convert.ToString(ViewState["LaiHanLC"])); 
            }
            set
            {
                ViewState["LaiHanLC"] = value.ToString();
            }        
        }

        /// <summary>
        /// 设置复选框列显隐
        /// </summary>
        public bool ShowCheck;

        /// <summary>
        /// 记录来函编号
        /// </summary>
        public string LaiHanBH 
        {
            get 
            {
                return Convert.ToString(ViewState["LaiHanBH"]);
            }
            set
            {
                ViewState["LaiHanBH"] = value;
            }
        }
        /// <summary>
        /// 记录井原用户号
        /// </summary>
        public string YuanYongHuH
        {
            get
            {
                return Convert.ToString(ViewState["YuanYongHuH"]);
            }
            set
            {
                ViewState["YuanYongHuH"] = value;
            }
        }
        /// <summary>
        /// 记录目标用户号
        /// </summary>
        public string TargetYongHuH
        {
            get
            {
                return Convert.ToString(ViewState["TargetYongHuH"]);
            }
            set
            {
                ViewState["TargetYongHuH"] = value;
            }
        }
        /// <summary>
        /// 记录目标用户名
        /// </summary>
        public string TargetYongHuM
        {
            get
            {
                return Convert.ToString(ViewState["TargetYongHuM"]);
            }
            set
            {
                ViewState["TargetYongHuM"] = value;
            }
        }

        /// <summary>
        /// 设置列表高度
        /// </summary>
        public int ListHeight
        {
            set
            {
                this.gvList.Settings.VerticalScrollableHeight = value;
            }
        }

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {

        }

        /// <summary>
       ///重新绑定
        /// </summary>
        public void BindData()
        {
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 清空数据
        /// </summary>
        public void ClearInfo()
        {
            this.dtSource = null;
            this.gvList.DataSource = null;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 验证
        /// </summary>
        /// <returns></returns>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            rs.IsSuccess = true;
            return rs;
        }
     
        /// <summary>
        /// 根据来函加载信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
            }
            else
            {
                this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH),laihanxx.I_LIUCHENGBH.ToString());
            } 
            this.dtSource = new SpHelper().P_QSLH_QSKBIAOXXHQ((int)this.LaiHanLX, laihanxx.S_LAIHANBH, BusinessTool.WType, laihanxx.S_BEIZHU).Tables[0];           
            this.BindData(); 
            
        }

        /// <summary>
        /// 添加申请信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void CreateShengQingXX(YS_LH_LAIHANXX laihanxx)
        {
            if (this.LaiHanLX == eLaiHanLX.水资源销取水口)
            {
                //先清除该来函旧的销表水表记录
                QS_LH_XIAOQSKSBXXProcess bllT2 = new QS_LH_XIAOQSKSBXXProcess();
                bllT2.DeleteQS_LH_XIAOQSKSBXXesDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
                List<QS_LH_XIAOQSKSBXX> list = new List<QS_LH_XIAOQSKSBXX>();
                foreach (DataRow row in this.dtSource.Rows)
                {
                    QS_LH_XIAOQSKSBXX item = new QS_LH_XIAOQSKSBXX();
                    item.S_LAIHANBH = laihanxx.S_LAIHANBH;
                    item.S_QUSHUIKBH = Convert.ToString(row["S_QUSHUIKBH"]);
                    item.S_SHUIBIAOBH = Convert.ToString(row["S_SHUIBIAOBH"]);
                    item.S_YONGHUH = Convert.ToString(row["S_YONGHUH"]);
                    item.S_YONGHUM = Convert.ToString(row["S_YONGHUM"]);
                    list.Add(item);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    bllT2.InsertOrUpdate(list[i]);
                }                
            }
            else if (this.LaiHanLX == eLaiHanLX.水资源取水口过户)
            {
                //先清除该来函旧的销表水表记录
                QS_LH_QUSHUIKGHSBXXProcess bllT2 = new QS_LH_QUSHUIKGHSBXXProcess();
                bllT2.DeleteQS_LH_QUSHUIKGHSBXXesDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
                List<QS_LH_QUSHUIKGHSBXX> list = new List<QS_LH_QUSHUIKGHSBXX>();
                foreach (DataRow row in this.dtSource.Rows)
                {
                    QS_LH_QUSHUIKGHSBXX item = new QS_LH_QUSHUIKGHSBXX();
                    item.S_LAIHANBH = laihanxx.S_LAIHANBH;
                    item.S_QUSHUIKBH = Convert.ToString(row["S_QUSHUIKBH"]);
                    item.S_SHUIBIAOBH = Convert.ToString(row["S_SHUIBIAOBH"]);
                    item.S_YONGHUH = Convert.ToString(row["S_YONGHUH"]);
                    item.S_YONGHUM = Convert.ToString(row["S_YONGHUM"]);
                    item.S_YONGHUHMB = this.TargetYongHuH;
                    item.S_YONGHUMMB = this.TargetYongHuM;
                    list.Add(item);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    bllT2.InsertOrUpdate(list[i]);
                }
            }
        }

        public void RegistTagetYongHu(string yonghuh,string yonghum)
        {
            this.TargetYongHuH = yonghuh;
            this.TargetYongHuM = yonghum;
        }

        #endregion        
    }
}